

#include "game.h"

void menu()
{
    printf("************************\n");
    printf("******  1. play   ******\n");
    printf("******  0. exit   ******\n");
    printf("************************\n");
}

void game()
{
    //存储数据--二维数组
    char board[ROW][COL];
    //初始化棋盘--初始化为空格
    InitBoard(board, ROW, COL);
    //打印下棋盘
    DisplayBoard(board, ROW, COL);
    char ret = 0;   //该变量用于获取游戏状态
    while (1)
    {
        //玩家、电脑对弈
        PlayerMove(board, ROW, COL);
        DisplayBoard(board, ROW, COL);  // 下一步打印一下
        //判断玩家输赢
        ret = IsWin(board, ROW, COL);
        if (ret != 'C')
        {
            break;
        }

        ComputerMove(board, ROW, COL);
        DisplayBoard(board, ROW, COL);  // 下一步打印一下
        //判断电脑输赢
        ret = IsWin(board, ROW, COL);
        if (ret != 'C')
        {
            break;
        }
    }
    if (ret == '*')
    {
        printf("玩家胜\n");
    }
    else if (ret == '#')
    {
        printf("电脑胜\n");
    }
    else
    {
        printf("平局\n");
    }
    DisplayBoard(board, ROW, COL);
}

int main()
{
    int input = 0;
    srand((unsigned int)time(NULL));

    do{
        menu();
        printf("请选择：");
        scanf("%d", &input);
        switch (input)
        {
            case 1:
                game();
                break;
            case 0:
                printf("退出游戏\n");
                break;
            default:
                printf("选择错误，重新选择\n");
                break;
        }
    }while(input);
    return 0;
}